package com.ying.dao.system;

import com.ying.po.system.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;


public interface UserRepository extends JpaRepository<User, Integer> {

    @Query(value = "select * from t_user where IS_DELETE is false", nativeQuery = true)
    public Page<User> getUserPageIsNotDeleted(Pageable pageable);

    @Query(value = "select * from t_user where IS_DELETE is false", nativeQuery = true)
    public List<User> findallisnotdelete();


    @Query(value = "select * from t_user where is_delete=0 and id=?1", nativeQuery = true)
    public Optional<User> findByIdAndIsNotDelete(Integer id);

    //    @Query(value = "select * from user where IS_DELETE is false and SEX=:user.sex and USERNAME like :user.username and EMAIL=:user.email and MOBILE=:user.mobile and STATUS=1", nativeQuery = true)
    @Query(value = "select * from t_user where SEX=:sex and IS_DELETE=0", nativeQuery = true)
    public Page<User> getQueryPage(Pageable pageable, Integer sex);

    @Query(value = "select * from t_user where USERNAME=:username and IS_DELETE=0", nativeQuery = true)
    public Page<User> findPageByUsername(Pageable pageable, String username);

    @Query(value = "select * from t_user where STATUS=:status and IS_DELETE=0", nativeQuery = true)
    public Page<User> findPageByStatus(Pageable pageable, Integer status);

    @Query(value = "select * from t_user where STATUS=:status and USERNAME=:username and IS_DELETE=0", nativeQuery = true)
    public Page<User> findPageByStatusAndUsername(Pageable pageable, Integer status, String username);

    @Query(value = "select * from t_user where USERNAME=:username and PASSWORD=:password and IS_DELETE=0", nativeQuery = true)
    User findByUsernameAndPassword(@Param("username") String username, @Param("password")String password);

    @Query(value = "select * from t_user where TYPE=:roleCode and IS_DELETE=0", nativeQuery = true)
    List<User> findByRoleCode(@Param("roleCode") Integer roleCode);
}
